package second.hash;

import java.util.ArrayList;
import java.util.List;

public class Solution03 {
    public int[] intersection(int[] nums1, int[] nums2) {
        boolean[] hash = new boolean[1001];
        for (int j : nums1) {
            hash[j] = true;
        }
        List<Integer> res = new ArrayList<>();
        for (int j : nums2) {
            if (hash[j]) {
                hash[j] = false;
                res.add(j);
            }
        }
        int[] resArr = new int[res.size()];
        for (int i = 0; i < res.size(); i++) {
            resArr[i] = res.get(i);
        }
        return resArr;
    }
}
